<template>
  <div class="dashboard">
    <el-row :gutter="12">
      <el-col :span="7">
        <lz-card title="分类商品数量(饼图)">
          <pie-echart :pieData="categoryGoodsCount"></pie-echart>
        </lz-card>
      </el-col>
      <el-col :span="10">
        <lz-card title="不同城市销量">
          <map-echart :mapData="addressGoodsSale"></map-echart>
        </lz-card>
      </el-col>
      <el-col :span="7">
        <lz-card title="分类商品数量(玫瑰图)">
          <rose-echart :roseData="categoryGoodsCount"></rose-echart>
        </lz-card>
      </el-col>
    </el-row>
    <el-row :gutter="12" class="content-bottom">
      <el-col :span="12">
        <lz-card title="分类商品的销量">
          <line-echart v-bind="categoryGoodsSale"></line-echart>
        </lz-card>
      </el-col>
      <el-col :span="12">
        <lz-card title="分类商品的收藏">
          <bar-echart v-bind="categoryGoodsFavor"></bar-echart>
        </lz-card>
      </el-col>
    </el-row>
  </div>
</template>

<script lang="ts">
import { computed, defineComponent } from 'vue'
import { useStore } from '@/store'
import lzCard from '@/base-ui/card'
import { pieEchart, roseEchart, lineEchart, barEchart, mapEchart } from '@/components/page-echarts'

export default defineComponent({
  components: {
    lzCard,
    pieEchart,
    roseEchart,
    lineEchart,
    barEchart,
    mapEchart
  },
  setup() {
    const store = useStore()
    // 请求数据
    store.dispatch('dashboard/getDashboardDataActions')

    // 获取数据
    const categoryGoodsCount = computed(() => {
      return store.state.dashboard.categoryGoodsCount.map((item: any) => {
        return { name: item.name, value: item.goodsCount }
      })
    })
    const categoryGoodsSale = computed(() => {
      const xLabels: string[] = []
      const values: any[] = []
      store.state.dashboard.categoryGoodsCount.forEach((item) => {
        xLabels.push(item.name)
        values.push(item.goodsCount)
      })
      return { xLabels, values }
    })
    const categoryGoodsFavor = computed(() => {
      const xLabels: string[] = []
      const values: any[] = []
      store.state.dashboard.categoryGoodsFavor.forEach((item) => {
        xLabels.push(item.name)
        values.push(item.goodsFavor)
      })
      return { xLabels, values }
    })
    const addressGoodsSale = computed(() => {
      return store.state.dashboard.addressGoodsSale.map((item: any) => {
        return item
      })
    })

    return {
      categoryGoodsCount,
      categoryGoodsSale,
      categoryGoodsFavor,
      addressGoodsSale
    }
  }
})
</script>

<style scoped lang="less">
.content-bottom {
  margin-top: 15px;
}
</style>
